import 'dart:async';

import 'package:get/get.dart';

import '../../routes/app_routes.dart';
import 'index_state.dart';

class IndexLogic extends GetxController {
  final IndexState state = IndexState();


  late Timer timer;

  @override
  void onInit() {
    startTimer();
    super.onInit();
  }

  @override
  void dispose() {
    stopTimer();
    super.dispose();
  }


  void startTimer() {
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      state.countdown();
      update();
      if(state.seconds == 0){
        stopTimer();
      }
    });
  }

  void stopTimer() {
    timer.cancel();
  }

  //跳转首页
  void goMain(){
    Get.offAllNamed(AppRoutes.MAIN);
  }
}
